package com.nulldev.util.web.HttpClient;

public interface HttpClientFlags<T> {

	public static final int HTTP_CLIENT_NOT_SUPPORTED = -1;
	public static final int HTTP_CLIENT_FALSE = 0;
	public static final int HTTP_CLIENT_TRUE = 1;

	/* */

	public static final int FEATURE_FLAG_OK_FORCE_CHUNKING = 10;
	public static final int FEATURE_FLAG_OK_FOLLOW_REDIRECTS = 11;
	public static final int FEATURE_FLAG_OK_FOLLOW_SSL_REDIRECTS = 12;
	public static final int FEATURE_FLAG_OK_USE_OLD_DECOMPRESSION_LOGIC = 12;
	public static final int FEATURE_FLAG_SPOOF_CHROMIUM = 13;
	public static final int FEATURE_FLAG_PREFER_QUIC = 14;
	public static final int FEATURE_FLAG_READABLE = 15;
	public static final int FEATURE_FLAG_READABLE_NIO = 16;
	public static final int FEATURE_FLAG_ENABLE_DEBUGGING = 17;
	public static final int FEATURE_FLAG_REQUEST_READ_API = 18;

	/* */

	public static final int FEATURE_FLAG_ENABLE_UPSTREAM_THROTTLING = 20;
	public static final int FEATURE_FLAG_ENABLE_DOWNSTREAM_THROTTLING = 21;
	public static final int FEATURE_FLAG_BACKPORT_ENABLE_INPUT_STREAM_MONITOR = 22;

	public default boolean isFeatureFlagSupported(final int feature) {
		return false;
	}

	public default Object getFeatureFlag(final int feature) {
		return HTTP_CLIENT_NOT_SUPPORTED;
	}

	public T setFeatureFlag(final int feature, final Object value);

	public T tryFeatureFlag(final int feature, final Object value);

	public default boolean _value_asBoolean(final Object value) {
		if (value instanceof Boolean)
			return (boolean) value;
		if (value instanceof Integer) {
			if (((int) value) == HTTP_CLIENT_TRUE)
				return true;
			if (((int) value) == HTTP_CLIENT_FALSE)
				return false;
		}
		throw new UnsupportedOperationException("Unsupported value: " + value);
	}

}
